#!/usr/bin/env python
# -*- coding: utf-8 -*-
import timeit
import matplotlib.pyplot as plt
import numpy as np
from sklearn.linear_model import LinearRegression

def pizza_plot():
    X = [[6], [8], [10], [14], [18]]
    y = [[7], [9], [13], [17.5], [18]]
    plt.figure()
    plt.title('Pizza price plooted against diameter')
    plt.xlabel('Diameter in inches')
    plt.ylabel('Price in dollars')
    plt.plot(X, y, 'k.')
    plt.axis([0, 25, 0, 25])
    plt.grid(True)
    plt.show()
    
def pizza_learn():
    X = [[6], [8], [10], [14], [18]]
    y = [[7], [9], [13], [17.5], [18]]
    model = LinearRegression()
    model.fit(X, y)
    print 'A 12'' pizza should cost: $%.2f' % model.predict([12])[0]
    print 'A 18'' pizza should cost: $%.2f' % model.predict([18])[0]
    print 'Residual sum of squares: %.2f' % np.mean((model.predict(X)-y) ** 2)
    print np.var([x[0] for x in X], ddof=1)
    print np.cov([x[0] for x in X], [i[0] for i in y])[0][1]
    X_test = [[8], [9], [11], [16], [12]]
    y_test = [[11], [8.5], [15], [18], [11]]
    print 'R-squared: %.4f' % model.score(X_test, y_test)
    

def main():
#     pizza_plot()
    pizza_learn()

if __name__ == '__main__':
    start = timeit.default_timer()
    
    main()
    
    stop = timeit.default_timer()
    print 'run time: %.10fs' % (stop - start)
    
